package com.xayy.health.core.enums;


import com.xayy.health.mgt.model.FractionIntervalScore;
import lombok.Getter;

import java.util.List;

/**
 * 评分规则类型
 *
 * @author dongxingli
 * createTime 2021/1/12
 * @version V1.0
 */
public enum ScoreRuleEnum {
    //故障等级
    FAULT(1, "故障等级"),
    //健康状态
    HEALTH(2, "健康状态"),
    //效能满意度
    EFFICACY(3, "效能满意度"),
    ;

    @Getter
    private Integer code;
    @Getter
    private String msg;

    ScoreRuleEnum(Integer code, String msg) {
        this.code = code;
        this.msg = msg;
    }

    public static String matchMsg(Integer code) {
        ScoreRuleEnum[] values = ScoreRuleEnum.values();
        for (ScoreRuleEnum value : values) {
            if (value.code.equals(code)) {
                return value.getMsg();
            }
        }
        return null;
    }

    public static String matchLevelStr(List<FractionIntervalScore> intervalList, int score) {
        for (FractionIntervalScore x : intervalList) {
            if (x.getStartScore() <= score && score <= x.getEndScore()) {
                return x.getFractionName();
            }
        }
        return "无";
    }

    public static String matchLevelStrByLevel(List<FractionIntervalScore> intervalList, int level) {
        for (FractionIntervalScore x : intervalList) {
            if (x.getLevel() == level) {
                return x.getFractionName();
            }
        }
        return "无";
    }
}
